﻿using UnityEngine;
using System.Collections;

public class attack : MonoBehaviour {
    // Use this for initialization
    private GameObject parent;
    private Animator p_animator;
    private int flag = 1;
    public int damage;
    private int damageType = 10;
    private string AttackName;
	void Start () {
        parent = transform.parent.gameObject;
        p_animator = parent.GetComponent<Animator>();
        
	}
	void Update () {   
	}
    public void SetDamageType(int type) {
        damageType = type;
    }
    public void SetString(string str) {
        AttackName = str;
    }
    void OnTriggerStay2D(Collider2D other) {
        if (transform.parent.gameObject.GetComponent<sc>().get_attacking() == 1)
        //if 用于判定伤害区域&&防止同一次攻击造成多次伤害
        {
            //transform.parent.gameObject.GetComponent<sc>().set_attacking();
            ////造成一次攻击之后修改attacking标志位，防止二次伤害

            string str = transform.parent.gameObject.GetComponent<sc>().GetAttackName();
            if (damageType == 0)
            {
                other.SendMessage("HardTime", 1);
                other.SendMessage("TakeDamage", 30);
                other.SendMessage("set_beattacked",AttackName);
            }
            else if (damageType == 1)
            {
                other.SendMessage("TakeDamage", 30);
                other.SendMessage("set_beattacked", AttackName);
                other.SendMessage("KnockFly", 5);
            }
            //other.GetComponent<health>().TakeDamage(damage);
            //找到受伤的角色，调用收到攻击的函数。
        }

    }
}
